home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / timidsrc.zip / dumb_c.c < prev    next >
C/C++ Source or Header  |  1996-05-20  |  4KB  |  166 lines

  1. /* 
  2.  
  3.     TiMidity -- Experimental MIDI to WAVE converter
  4.     Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     dumb_c.c
  21.     Minimal control mode -- no interaction, just prints out messages.
  22.     */
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <stdarg.h>
  27.  
  28. #include "config.h"
  29. #include "common.h"
  30. #include "output.h"
  31. #include "controls.h"
  32. #include "instrum.h"
  33. #include "playmidi.h"
  34.  
  35. static void ctl_refresh(void);
  36. static void ctl_total_time(int tt);
  37. static void ctl_master_volume(int mv);
  38. static void ctl_file_name(char *name);
  39. static void ctl_current_time(int ct);
  40. static void ctl_note(int v);
  41. static void ctl_program(int ch, int val);
  42. static void ctl_volume(int channel, int val);
  43. static void ctl_expression(int channel, int val);
  44. static void ctl_panning(int channel, int val);
  45. static void ctl_sustain(int channel, int val);
  46. static void ctl_pitch_bend(int channel, int val);
  47. static void ctl_reset(void);
  48. static int ctl_open(int using_stdin, int using_stdout);
  49. static void ctl_close(void);
  50. static int ctl_read(int32 *valp);
  51. static int cmsg(int type, int verbosity_level, char *fmt, ...);
  52.  
  53. /**********************************/
  54. /* export the interface functions */
  55.  
  56. #define ctl dumb_control_mode
  57.  
  58. ControlMode ctl= 
  59. {
  60.   "dumb interface", 'd',
  61.   1,0,0,
  62.   ctl_open,dumb_pass_playing_list, ctl_close, ctl_read, cmsg,
  63.   ctl_refresh, ctl_reset, ctl_file_name, ctl_total_time, ctl_current_time, 
  64.   ctl_note, 
  65.   ctl_master_volume, ctl_program, ctl_volume, 
  66.   ctl_expression, ctl_panning, ctl_sustain, ctl_pitch_bend
  67. };
  68.  
  69. static FILE *infp=stdin, *outfp=stdout; /* infp isn't actually used yet */
  70.  
  71. static int ctl_open(int using_stdin, int using_stdout)
  72. {
  73.   if (using_stdin && using_stdout)
  74.     infp=outfp=stderr;
  75.   else if (using_stdout)
  76.     outfp=stderr;
  77.   else if (using_stdin)
  78.     infp=stdout;
  79.  
  80.   ctl.opened=1;
  81.   return 0;
  82. }
  83.  
  84. static void ctl_close(void)
  85.   fflush(outfp);
  86.   ctl.opened=0;
  87. }
  88.  
  89. static int ctl_read(int32 *valp)
  90. {
  91.   return RC_NONE;
  92. }
  93.  
  94. static int cmsg(int type, int verbosity_level, char *fmt, ...)
  95. {
  96.   va_list ap;
  97.   if ((type==CMSG_TEXT || type==CMSG_INFO || type==CMSG_WARNING) &&
  98.       ctl.verbosity<verbosity_level)
  99.     return 0;
  100.   va_start(ap, fmt);
  101.   if (!ctl.opened)
  102.     {
  103.       vfprintf(stderr, fmt, ap);
  104.       fprintf(stderr, "\n");
  105.     }
  106.   else
  107.     {
  108.       vfprintf(outfp, fmt, ap);
  109.       fprintf(outfp, "\n");
  110.     }
  111.   va_end(ap);
  112.   return 0;
  113. }
  114.  
  115. static void ctl_refresh(void) { }
  116.  
  117. static void ctl_total_time(int tt)
  118. {
  119.   int mins, secs;
  120.   if (ctl.trace_playing)
  121.     {
  122.       secs=tt/play_mode->rate;
  123.       mins=secs/60;
  124.       secs-=mins*60;
  125.       fprintf(outfp, "Total playing time: %3d min %02d s\n", mins, secs);
  126.     }
  127. }
  128.  
  129. static void ctl_master_volume(int mv) {}
  130.  
  131. static void ctl_file_name(char *name)
  132. {
  133.   if (ctl.verbosity>=0 || ctl.trace_playing)
  134.     fprintf(outfp, "Playing %s\n", name);
  135. }
  136.  
  137. static void ctl_current_time(int ct)
  138. {
  139.   int mins, secs;
  140.   if (ctl.trace_playing)
  141.     {
  142.       secs=ct/play_mode->rate;
  143.       mins=secs/60;
  144.       secs-=mins*60;
  145.       fprintf(outfp, "\r%3d:%02d", mins, secs);
  146.       fflush(outfp);
  147.     }
  148. }
  149.  
  150. static void ctl_note(int v) {}
  151.  
  152. static void ctl_program(int ch, int val) {}
  153.  
  154. static void ctl_volume(int channel, int val) {}
  155.  
  156. static void ctl_expression(int channel, int val) {}
  157.  
  158. static void ctl_panning(int channel, int val) {}
  159.  
  160. static void ctl_sustain(int channel, int val) {}
  161.  
  162. static void ctl_pitch_bend(int channel, int val) {}
  163.  
  164. static void ctl_reset(void) {}
  165.